/*
 * FileName: LockSuportDemo.java
 * Author:   zzw
 * Date:     2018年05月14日
 * Description:
 */
package com.zzw.thread;

import java.util.concurrent.locks.LockSupport;

/**
 * 〈〉<br>
 * 〈〉
 *
 * @author zzw
 * @see [相关类/方法]（可选）
 * @since [产品/模块版本]（可选）
 */
public class LockSuportDemo {

    private static Object u = new Object();
    private static ChangeObjectThread t1 = new ChangeObjectThread("t1");
    private static ChangeObjectThread t2 = new ChangeObjectThread("t2");

    public static class ChangeObjectThread extends Thread{
        public ChangeObjectThread(String name){
            super.setName(name);
        }

        @Override
        public void run() {
            synchronized (u){
                System.out.println("in" + getName());
                LockSupport.park();
                if(Thread.interrupted()){
                    System.out.println(getName() + "被中断了");
                }
            }
            System.out.println(getName() + "执行结束");
        }
    }

    public static void main(String[] args) throws InterruptedException {
        t1.start();
        Thread.sleep(100);
        t2.start();
        t1.interrupt();
        //LockSupport.unpark(t1);
        LockSupport.unpark(t2);
        //t1.join();
        //t2.join();
    }
}
